var t = require("../../../../@babel/runtime/helpers/interopRequireWildcard")(require("../../../../ec-canvas/echarts")), a = getApp(), e = null, i = null, s = null, o = null, n = null;

Page({
    data: {
        show: !1,
        showTitle: "",
        showContent: "",
        showID: "",
        card_id: "",
        nowTab: 0,
        url: "plugin.business-card.frontend.controllers.statistics.visit.get-list",
        active: 0,
        visit: {
            diagram: {},
            statistics: {}
        },
        visitList: [],
        reliable: {},
        save: {},
        share: {},
        collect: {
            diagram: {}
        },
        collectList: [],
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        ec1: {
            onInit: function(a, i, s) {
                return e = t.init(a, null, {
                    width: i,
                    height: s
                }), a.setChart(e), e;
            }
        },
        ec2: {
            onInit: function(a, e, s) {
                return i = t.init(a, null, {
                    width: 317,
                    height: 350
                }), a.setChart(i), i;
            }
        },
        ec3: {
            onInit: function(a, e, i) {
                return s = t.init(a, null, {
                    width: 317,
                    height: 350
                }), a.setChart(s), s;
            }
        },
        ec4: {
            onInit: function(a, e, i) {
                return o = t.init(a, null, {
                    width: 317,
                    height: 350
                }), a.setChart(o), o;
            }
        },
        ec5: {
            onInit: function(a, e, i) {
                return n = t.init(a, null, {
                    width: 317,
                    height: 350
                }), a.setChart(n), n;
            }
        }
    },
    onLoad: function(t) {
        this.setData({
            card_id: t.card_id
        }), this.getEchartDate(), this.getCartAction(), this.getcollect(), this.getListDate();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {},
    init_lineCharts: function() {
        var t = {
            title: {
                text: "",
                textStyle: {
                    color: "#0094ff",
                    fontSize: 12
                }
            },
            tooltip: {
                trigger: "axis"
            },
            grid: {
                left: "3%",
                right: "6%",
                bottom: "3%",
                containLabel: !0
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: "category",
                boundaryGap: !1,
                data: this.data.visit.diagram.date || [ "周一", "周二", "周三", "周四", "周五", "周六", "周日" ]
            },
            yAxis: {
                type: "value"
            },
            series: [ {
                type: "line",
                areaStyle: {},
                data: this.data.visit.diagram.num
            } ]
        };
        e.setOption(t);
    },
    chooseTab: function(t) {
        var a = t.detail.index;
        if (this.setData({
            nowTab: a
        }), 0 === a) this.setData({
            url: "plugin.business-card.frontend.controllers.statistics.visit.get-list"
        }); else {
            if (2 !== a) {
                var e = {
                    title: {
                        text: "",
                        textStyle: {
                            color: "#0094ff",
                            fontSize: 12
                        }
                    },
                    tooltip: {
                        trigger: "axis"
                    },
                    grid: {
                        left: "3%",
                        right: "6%",
                        bottom: "3%",
                        containLabel: !0
                    },
                    toolbox: {
                        feature: {
                            saveAsImage: {}
                        }
                    },
                    xAxis: {
                        type: "category",
                        boundaryGap: !1,
                        data: this.data.visit.diagram.date || [ "周一", "周二", "周三", "周四", "周五", "周六", "周日" ]
                    },
                    yAxis: {
                        type: "value"
                    },
                    series: [ {
                        type: "line",
                        areaStyle: {},
                        data: this.data.visit.diagram.num
                    } ]
                };
                return i.setOption(e), s.setOption(e), void o.setOption(e);
            }
            this.setData({
                url: "plugin.business-card.frontend.controllers.statistics.collection.get-list"
            });
        }
        this.setData({
            showID: "",
            page: 1
        }), this.getListDate();
    },
    showMore: function(t) {
        var a = t.target.dataset.id || t.currentTarget.dataset.id;
        a === this.data.showID ? this.setData({
            showID: ""
        }) : this.setData({
            showID: a
        });
    },
    showWeChat: function(t) {
        var a = t.target.dataset.name || t.currentTarget.dataset.name, e = t.target.dataset.item || t.currentTarget.dataset.item, i = t.target.dataset.str || t.currentTarget.dataset.str;
        this.setData({
            show: !0,
            showTitle: a
        }), "微信" === a ? i ? this.setData({
            showContent: e.collect_card.card_wechat
        }) : this.setData({
            showContent: e.visitor_card.card_wechat
        }) : "电话" === a && (i ? this.setData({
            showContent: e.collect_card.card_mobile
        }) : this.setData({
            showContent: e.visitor_card.card_mobile
        }));
    },
    getEchartDate: function() {
        var t = this, e = a.getNetAddresss("plugin.business-card.frontend.controllers.statistics.visit.index");
        e += "&card_id=" + this.data.card_id, a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    visit: e.data
                }), t.init_lineCharts()) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getListDate: function() {
        var t = this, e = a.getNetAddresss(this.data.url);
        e += "&card_id=" + this.data.card_id + "&page=1", a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    if (t.setData({
                        isLoadMore: !0,
                        total_page: e.data.last_page
                    }), t.data.total_page || t.setData({
                        total_page: 0
                    }), 0 === t.data.nowTab) t.setData({
                        visitList: e.data.data
                    }); else if (2 === t.data.nowTab) {
                        t.setData({
                            collectList: e.data.data
                        });
                        var i = {
                            title: {
                                text: "",
                                textStyle: {
                                    color: "#0094ff",
                                    fontSize: 12
                                }
                            },
                            tooltip: {
                                trigger: "axis"
                            },
                            grid: {
                                left: "3%",
                                right: "6%",
                                bottom: "3%",
                                containLabel: !0
                            },
                            toolbox: {
                                feature: {
                                    saveAsImage: {}
                                }
                            },
                            xAxis: {
                                type: "category",
                                boundaryGap: !1,
                                data: t.data.collect.diagram.date || [ "周一", "周二", "周三", "周四", "周五", "周六", "周日" ]
                            },
                            yAxis: {
                                type: "value"
                            },
                            series: [ {
                                type: "line",
                                areaStyle: {},
                                data: t.data.collect.diagram.num
                            } ]
                        };
                        n.setOption(i);
                    }
                } else wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getCartAction: function() {
        var t = this, e = a.getNetAddresss("plugin.business-card.frontend.controllers.statistics.card-action.index");
        e += "&card_id=" + this.data.card_id, a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    reliable: e.data.reliable,
                    save: e.data.save,
                    share: e.data.share
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getcollect: function() {
        var t = this, e = a.getNetAddresss("plugin.business-card.frontend.controllers.statistics.collection.index");
        e += "&card_id=" + this.data.card_id, a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    collect: e.data
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var t = this;
        if (this.setData({
            isLoadMore: !1
        }), !(this.data.page >= this.data.total_page)) {
            var e = this.data.page + 1;
            this.setData({
                page: e
            });
            var i = a.getNetAddresss(this.data.url);
            i += "&card_id=" + this.data.card_id + "&page=" + this.data.page, a._getNetWork({
                url: i,
                success: function(a) {
                    t.setData({
                        isLoadMore: !0
                    });
                    var e = a.data;
                    if (1 == e.result) {
                        var i = e.data.data;
                        if (0 === t.data.nowTab) {
                            var s = i.concat(t.data.visitList);
                            t.setData({
                                visitList: s
                            });
                        } else if (2 === t.data.nowTab) {
                            var o = i.concat(t.data.collectList);
                            t.setData({
                                collectList: o
                            });
                        }
                    } else {
                        wx.showToast({
                            title: e.msg,
                            icon: "none"
                        });
                        var n = t.data.page - 1;
                        t.setData({
                            page: n,
                            isLoadMore: !1
                        });
                    }
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    goToBackCard: function(t) {
        var a = t.target.dataset.item || t.currentTarget.dataset.item;
        "collect" === (t.target.dataset.str || t.currentTarget.dataset.str) ? a.collect_card ? wx.navigateTo({
            url: "/packageB/member/business_card/BusinessCard/BusinessCard?mark=card&card_id=" + a.collect_card.id
        }) : wx.showToast({
            title: "该会员未开启名片",
            icon: "none"
        }) : a.visitor_card ? wx.navigateTo({
            url: "/packageB/member/business_card/BusinessCard/BusinessCard?mark=card&card_id=" + a.visitor_card.id
        }) : wx.showToast({
            title: "该会员未开启名片",
            icon: "none"
        });
    },
    closePu: function() {
        this.setData({
            show: !1
        });
    }
});